//
//  RegisterOneVC.m
//  qwe
//
//  Created by 谢志振 on 16/8/12.
//  Copyright © 2016年 谢志振. All rights reserved.
//

#import "RegisterOneVC.h"
#import "SDAutoLayout.h"
#import "RegisterTwoVC.h"
#import "VDJConstant.h"
#import "JQProgressHUD.h"
@interface RegisterOneVC ()
@property UIButton * lastBtn;
@property (nonatomic, copy) NSString * iDStr;
@property (nonatomic, copy) NSString * telStr;
@property  BOOL  isAgreePrivacy;
@end
@implementation RegisterOneVC
- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    [self baseUI];
    
}
- (void)onTapPrivacyButton:(UIButton *)sender
{
    sender.selected = !sender.selected;
    
    _isAgreePrivacy = sender.selected;
}
- (void)onTapNextButton
{
    if (!_isAgreePrivacy) {
        [JQProgressHUD showErrorMessage:@"请同意条款，隐私声明"];
        return;
    }
    [self.navigationController pushViewController:[[RegisterTwoVC alloc]init] animated:YES];
}
- (void)onTapIDButton:(UIButton *)sender
{
    if (!_lastBtn) {
        _lastBtn = sender;
        sender.selected = !sender.selected;
        return;
    }
    if (_lastBtn == sender) {
        return;
    }
    
    sender.selected = YES;
    _lastBtn.selected = NO;
    _lastBtn = sender;
    
}
- (void)baseUI
{
    UIImageView * bg = [[UIImageView alloc]initWithFrame:self.view.bounds];
    bg.image = [UIImage imageNamed:@"登录背景"];
    [self.view addSubview:bg];
    
    //账号
    UIImageView * phoneImage = [UIImageView new];
    phoneImage.image = [UIImage imageNamed:@"手机号"];
    [self.view addSubview:phoneImage];
    
    UILabel * verticalLine = [UILabel new];
    verticalLine.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:verticalLine];
    
    UITextField * accountTF = [UITextField new];
    accountTF.borderStyle = UITextBorderStyleNone;
    accountTF.textColor = [UIColor whiteColor];
    accountTF.font = [UIFont systemFontOfSize:12];
    [accountTF setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    accountTF.placeholder = @"请输入帐号";
    [self.view addSubview:accountTF];
    
    UILabel * horizontalLine = [UILabel new];
    horizontalLine.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:horizontalLine];
    
    horizontalLine.sd_layout.centerYEqualToView(self.view).centerXEqualToView(self.view).heightIs(1).widthRatioToView(self.view,0.6f);
    phoneImage.sd_layout.bottomSpaceToView(horizontalLine,8).leftEqualToView(horizontalLine).heightIs(15).widthEqualToHeight();
    verticalLine.sd_layout.centerYEqualToView(phoneImage).leftSpaceToView(phoneImage,8).heightRatioToView(phoneImage,0.8f).widthIs(1);
    accountTF.sd_layout.centerYEqualToView(phoneImage).rightEqualToView(horizontalLine).heightRatioToView(phoneImage,1.f).leftSpaceToView(verticalLine,8);
    
    //账号
    UILabel * IDLabel = [UILabel new];
    IDLabel.textColor = [UIColor whiteColor];
    IDLabel.font = [UIFont systemFontOfSize:12];
    IDLabel.text = @"我的身份:";
    [self.view addSubview:IDLabel];
    
    
    UILabel * horizontalLine2 = [UILabel new];
    horizontalLine2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:horizontalLine2];
    
    horizontalLine2.sd_layout.bottomSpaceToView(phoneImage,30).centerXEqualToView(self.view).heightIs(1).widthRatioToView(self.view,0.6f);
    IDLabel.sd_layout.leftEqualToView(horizontalLine2).bottomSpaceToView(horizontalLine2,8).heightIs(15).widthIs(55);
    
    
    NSArray * titleArr = @[@"家长",@"学生",@"老师"];
    UIView * referenceView = IDLabel;
    for (int i = 0; i < 3; i ++) {
        UIButton * btn = [UIButton new];
        [btn setTitle:titleArr[i] forState:0];
        [btn setImage:[UIImage imageNamed:@"框"] forState:0];
        [btn setImage:[UIImage imageNamed:@"钩"] forState:UIControlStateSelected];
        btn.titleLabel.font = [UIFont systemFontOfSize:11];
        [btn addTarget:self action:@selector(onTapIDButton:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = i + 1;
        [self.view addSubview:btn];
        btn.sd_layout.leftSpaceToView(referenceView,0).heightIs(15).widthIs((self.view.frame.size.width*0.6 - 55)/3.f).centerYEqualToView(referenceView);
        btn.imageView.sd_layout.leftEqualToView(btn).centerYEqualToView(btn).heightIs(13).widthEqualToHeight();
        btn.titleLabel.sd_layout.rightEqualToView(btn).centerYEqualToView(btn).leftSpaceToView(btn.imageView,2).heightRatioToView(btn,1.f);
        referenceView = btn;

    }
    //隐私声明
    UIButton * privacy = [UIButton new];
    [privacy setTitle:@"我同意服务条款，隐私声明" forState:0];
    [privacy setImage:[UIImage imageNamed:@"框"] forState:0];
    [privacy setImage:[UIImage imageNamed:@"钩"] forState:UIControlStateSelected];
    privacy.titleLabel.font = [UIFont systemFontOfSize:10];
    [privacy addTarget:self action:@selector(onTapPrivacyButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:privacy];
    privacy.sd_layout.leftEqualToView(horizontalLine).heightIs(15).widthIs(160).topSpaceToView(horizontalLine,5);
    privacy.imageView.sd_layout.leftEqualToView(privacy).centerYEqualToView(privacy).heightIs(13).widthEqualToHeight();
    privacy.titleLabel.sd_layout.rightEqualToView(privacy).centerYEqualToView(privacy).leftSpaceToView(privacy.imageView,5).heightRatioToView(privacy,1.f);
    
    //下一步
    UIButton * nextStep = [UIButton new];
    [nextStep setTitle:@"下 一 步" forState:0];
    [nextStep setTitleColor:kGetColor(43, 130, 211) forState:0];
    [nextStep setBackgroundImage:[UIImage imageNamed:@"登录按钮"] forState:0];
    nextStep.titleLabel.font = [UIFont systemFontOfSize:16];
    [nextStep addTarget:self action:@selector(onTapNextButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextStep];
    nextStep.sd_layout.leftEqualToView(horizontalLine).rightEqualToView(horizontalLine).heightIs(40).topSpaceToView(privacy,30);

}
@end
